home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / text / hyper / hsc_source.lha / hsc / source / hsclib / lmessage.c < prev    next >
C/C++ Source or Header  |  1996-12-04  |  14KB  |  462 lines

  1. /*
  2.  * hsclib/message.c
  3.  *
  4.  * message functions for hsc
  5.  *
  6.  * Copyright (C) 1995,96  Thomas Aglassinger
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  * updated: 31-Oct-1996
  23.  * created: 10-Mar-1996
  24.  *
  25.  * NOTE: see "hsclib/msgid.h" for message-id's and
  26.  *       how a message-id is build.
  27.  */
  28.  
  29. #define NOEXTERN_HSCLIB_MESSAGE_H
  30.  
  31. #include "hsclib/inc_base.h"
  32.  
  33. #include "ugly/returncd.h"
  34.  
  35. static VOID msg_tag(EXPSTR * msgstr, CONSTRPTR tagname)
  36. {
  37.     app_estr(msgstr, "tag <");
  38.     app_estr(msgstr, tagname);
  39.     app_estr(msgstr, ">");
  40. }
  41.  
  42. static VOID msg_endtag(EXPSTR * msgstr, CONSTRPTR tagname)
  43. {
  44.     app_estr(msgstr, "end tag </");
  45.     app_estr(msgstr, tagname);
  46.     app_estr(msgstr, ">");
  47. }
  48.  
  49. static VOID msg_attr(EXPSTR * msgstr, CONSTRPTR attrname)
  50. {
  51.     app_estr(msgstr, "attribute ");
  52.     app_estr(msgstr, attrname);
  53. }
  54.  
  55. static VOID msg_entity(EXPSTR * msgstr, CONSTRPTR entname)
  56. {
  57.     app_estr(msgstr, "entity `");
  58.     app_estr(msgstr, entname);
  59.     app_estr(msgstr, "'");
  60. }
  61.  
  62. static VOID msg_idname(EXPSTR * msgstr, CONSTRPTR idname)
  63. {
  64.     app_estr(msgstr, "id ");
  65.     app_estr(msgstr, "\"#");
  66.     app_estr(msgstr, idname);
  67.     app_estrch(msgstr, '"');
  68. }
  69.  
  70. /*
  71.  * hsc_message
  72.  *
  73.  * create message string and send it to call-back
  74.  *
  75.  * legal placeholders inside format:
  76.  *  %A ptr to HSCATTR
  77.  *  %a string for attribute-name
  78.  *  %d dezimal number (LONG)
  79.  *  %E ptr to HSCENT
  80.  *  %e string to entity-name
  81.  *  %i string to id-name
  82.  *  %q quoted string
  83.  *  %s string
  84.  *  %T ptr to HSCTAG
  85.  *  %t string for tag-name
  86.  *
  87.  * example:
  88.  * ---
  89.  *  HSCTAG *mytag;
  90.  *  STRPTR expected_tag = "dummy";
  91.  *
  92.  *  hsc_message( hp, MSG_my_tag_expected,
  93.  *               "Expected tag %T insted of %t",
  94.  *               mytag, expected_tag );
  95.  * ---
  96.  */
  97. VOID hsc_message(HSCPRC * hp, HSCMSG_ID msg_id, const char *format,...)
  98. {
  99. #if 1
  100.     HSCMSG_CLASS msg_class = hsc_get_msg_class(hp, msg_id);
  101. #else /* TODO: remove this */
  102.     HSCMSG_CLASS msg_class = msg_id & MASK_MSG_CLASS;
  103. #endif
  104.     INFILE *msg_inpf = NULL;
  105.     STRPTR msg_fname = "unknown";
  106.     ULONG msg_x = 0;
  107.     ULONG msg_y = 0;
  108.     BOOL disp_msg = TRUE;       /* flag, if message really */
  109.     /* should be displayed */
  110.     if (hp->fatal)
  111.     {
  112.  
  113.         /* oppress all messages after fatal errors */
  114.         disp_msg = FALSE;
  115.     }
  116.     else if (
  117.                 (hsc_get_msg_ignore(hp, msg_id))
  118.                 &&
  119.                 (hsc_get_msg_class(hp, msg_id) <= MSG_WARN)
  120.         )
  121.     {
  122.         /* oppress message if it is marked as ignored
  123.          * and it is no ERROR/FATAL message
  124.          */
  125.         D(fprintf(stderr, DHL "ignore msg#%ld: ignore enabled\n",
  126.                   msg_id & MASK_MESSAGE));
  127.         disp_msg = FALSE;
  128.     }
  129.     else if (((msg_class == MSG_NOTE) && (hp->msg_ignore_notes))
  130.              || ((msg_class == MSG_STYLE) && (hp->msg_ignore_style))
  131.              || ((msg_class == MSG_PORT) && (hp->msg_ignore_port))
  132.         )
  133.     {
  134.         /* oppress message if it's class is
  135.          * marked as to be ignored */
  136.         D(fprintf(stderr, DHL "ignore msg#%ld: ignore whole class\n",
  137.                   msg_id & MASK_MESSAGE));
  138.         disp_msg = FALSE;
  139.     }
  140.  
  141.     if (disp_msg)
  142.     {
  143.         va_list ap;
  144.  
  145.         /* increase message-counter */
  146.         hp->msg_count++;
  147.  
  148.         /* set fatal-flag, if this is a fatal message */
  149.         if (msg_id > MSG_FATAL)
  150.             hp->fatal = TRUE;
  151.  
  152.         /* clear message buffer */
  153.         clr_estr(hp->curr_msg);
  154.  
  155.         /* create message string */
  156.         va_start(ap, format);
  157.         while (format[0])
  158.         {
  159.             if (format[0] == '%')
  160.             {
  161.                 STRPTR s = NULL;
  162.                 HSCTAG *tag = NULL;
  163.                 HSCATTR *attr = NULL;
  164.                 HSCENT *ent = NULL;
  165.  
  166.                 format++;
  167.                 switch (format[0])
  168.                 {
  169.  
  170.                 case 'd':
  171.                     /*
  172.                      * append decimal number
  173.                      */
  174.                     app_estr(hp->curr_msg,
  175.                              long2str(va_arg(ap, LONG)));
  176.                     break;
  177.  
  178.                 case 'q':
  179.                     /*
  180.                      * append quoted string
  181.                      */
  182.                     s = va_arg(ap, STRPTR);
  183.  
  184.                     app_estrch(hp->curr_msg, '`');
  185.                     while (s[0])
  186.                     {
  187.                         switch (s[0])
  188.                         {
  189.  
  190.                         case '\n':
  191.                             app_estr(hp->curr_msg, "\\n");
  192.                             break;
  193.                         case '\"':
  194.                             app_estr(hp->curr_msg, "\\\"");
  195.                             break;
  196.                         default:
  197.                             if (s[0] < ' ')
  198.                             {
  199.                                 app_estrch(hp->curr_msg, '\\');
  200.                                 app_estr(hp->curr_msg,
  201.                                          long2str((LONG) s[0]));
  202.                                 app_estrch(hp->curr_msg, ';');
  203.                             }
  204.                             else
  205.                                 app_estrch(hp->curr_msg, s[0]);
  206.                         }
  207.                         s++;    /* process next char */
  208.                     }
  209.                     app_estrch(hp->curr_msg, '\'');
  210.  
  211.                     break;
  212.  
  213.                 case 's':
  214.                     /*
  215.                      * append simple string
  216.                      */
  217.                     app_estr(hp->curr_msg, va_arg(ap, STRPTR));
  218.                     break;
  219.  
  220.                 case 'T':
  221.                     /* append tag-pointer */
  222.                     tag = va_arg(ap, HSCTAG *);
  223.                     msg_tag(hp->curr_msg, tag->name);
  224.                     break;
  225.  
  226.                 case 't':
  227.                     /* append tag */
  228.                     msg_tag(hp->curr_msg, va_arg(ap, STRPTR));
  229.                     break;
  230.  
  231.                 case 'C':
  232.                     /* append end tag-pointer */
  233.                     tag = va_arg(ap, HSCTAG *);
  234.                     msg_endtag(hp->curr_msg, tag->name);
  235.                     break;
  236.  
  237.                 case 'c':
  238.                     /* append end tag */
  239.                     msg_endtag(hp->curr_msg, va_arg(ap, STRPTR));
  240.                     break;
  241.  
  242.                 case 'A':
  243.                     /* append attribute-pointer */
  244.                     attr = va_arg(ap, HSCATTR *);
  245.                     msg_attr(hp->curr_msg, attr->name);
  246.                     break;
  247.  
  248.                 case 'a':
  249.                     /* append attribute */
  250.                     msg_attr(hp->curr_msg, va_arg(ap, STRPTR));
  251.                     break;
  252.  
  253.                 case 'E':
  254.                     /* append entity-pointer */
  255.                     ent = va_arg(ap, HSCENT *);
  256.                     msg_entity(hp->curr_msg, ent->name);
  257.                     break;
  258.  
  259.                 case 'e':
  260.                     /* append entity */
  261.                     msg_entity(hp->curr_msg, va_arg(ap, STRPTR));
  262.                     break;
  263.  
  264.                 case 'i':
  265.                     /* append ID */
  266.                     msg_idname(hp->curr_msg, va_arg(ap, STRPTR));
  267.                     break;
  268.  
  269.                 case 'j':
  270.                     /* append jerk/prostitute */
  271.                     if (hp->prostitute)
  272.                         app_estr(hp->curr_msg, "prostitute");
  273.                     else
  274.                         app_estr(hp->curr_msg, "jerk");
  275.                     break;
  276.  
  277.                 default:
  278.                     /*
  279.                      * append unknown
  280.                      */
  281.                     app_estrch(hp->curr_msg, '%');
  282.                     if (format[0] && (format[0] != '%'))
  283.                     {
  284.                         app_estrch(hp->curr_msg, '%');
  285.                         format--;
  286.                     }
  287.                     break;
  288.                 }
  289.             }
  290.             else
  291.                 app_estrch(hp->curr_msg, format[0]);
  292.  
  293.             if (format[0])
  294.                 format++;
  295.         }
  296.         va_end(format);
  297.  
  298.         /* evaluate message position */
  299.         if (hp->inpf)
  300.         {
  301.             msg_inpf = hp->inpf;
  302.             msg_fname = infget_fname(msg_inpf);
  303.  
  304.             /* is parent file for position? */
  305.             if (!strncmp(msg_fname, PARENT_FILE_ID,
  306.                          strlen(PARENT_FILE_ID)))
  307.             {
  308.                 /* use position of first file on stack */
  309.                 msg_inpf = (INFILE *) dln_data(dll_first(hp->inpf_stack));
  310.                 msg_fname = infget_fname(msg_inpf);
  311.                 D(fprintf(stderr, DHL "msg from spec.file\n"));
  312.             }
  313.             msg_x = infget_wx(msg_inpf) + 1;
  314.             msg_y = infget_wy(msg_inpf) + 1;
  315.         }
  316.         else
  317.         {
  318.             msg_fname = NULL;
  319.             msg_x = 0;
  320.             msg_y = 0;
  321.         }
  322.  
  323.         /* send message via callback */
  324.         if (hp->CB_message)
  325.  
  326.             (*(hp->CB_message))
  327.                 (hp,
  328.                  msg_class,
  329.                  msg_id & MASK_MESSAGE,
  330.                  msg_fname, msg_x, msg_y,
  331.                  estr2str(hp->curr_msg)
  332.                 );
  333.  
  334.         /* process nested files */
  335.         if (hp->CB_message_ref)
  336.         {
  337.             DLNODE *nd = dll_first(hp->inpf_stack);
  338.  
  339.             while (nd)
  340.             {
  341.                 msg_inpf = dln_data(nd);
  342.                 msg_fname = infget_fname(msg_inpf);
  343.                 msg_x = infget_wx(msg_inpf) + 1;
  344.                 msg_y = infget_wy(msg_inpf) + 1;
  345.  
  346.                 (*(hp->CB_message_ref))
  347.                     (hp,
  348.                      msg_class,
  349.                      msg_id & MASK_MESSAGE,
  350.                      msg_fname, msg_x, msg_y,
  351.                      ""
  352.                     );
  353.  
  354.                 nd = dln_next(nd);
  355.             }
  356.         }
  357.     }
  358.     else
  359.     {
  360.         D(fprintf(stderr, DHL "suppressed msg#%ld\n", msg_id & MASK_MESSAGE));
  361.     }
  362. }
  363.  
  364. /*
  365.  *-------------------------------------
  366.  * often occurable errors & messages
  367.  *-------------------------------------
  368.  */
  369.  
  370. VOID hsc_msg_eof(HSCPRC * hp, STRPTR descr)
  371. {
  372.     STRPTR eoftxt = "unexpected end of file";
  373.  
  374.     if (descr)
  375.         hsc_message(hp, MSG_UNEX_EOF, "%s (%s)", eoftxt, descr);
  376.     else
  377.         hsc_message(hp, MSG_UNEX_EOF, "%s", eoftxt);
  378. }
  379.  
  380. VOID hsc_msg_illg_whtspc(HSCPRC * hp)
  381. {
  382.     hsc_message(hp, MSG_ILLG_WHTSPC, "illegal white space");
  383. }
  384.  
  385. VOID hsc_msg_stripped_tag(HSCPRC * hp, HSCTAG * tag, STRPTR why)
  386. {
  387.     if (why)
  388.         hsc_message(hp, MSG_TAG_STRIPPED,
  389.                     "stripped tag %T (%s)", tag, why);
  390.     else
  391.         hsc_message(hp, MSG_TAG_STRIPPED,
  392.                     "stripped tag %T", tag);
  393. }
  394.  
  395. VOID hsc_msg_unkn_attr(HSCPRC * hp, STRPTR attr)
  396. {
  397.     hsc_message(hp, MSG_UNKN_ATTR,
  398.                 "unknown %a", attr);
  399. }
  400.  
  401. #if 1                           /* TODO: get rid of this */
  402. VOID hsc_msg_eol(HSCPRC * hp)
  403. {
  404.     hsc_message(hp, MSG_UNEX_EOL,
  405.                 "unexpected end of line");
  406. }
  407. #endif
  408.  
  409. VOID hsc_msg_noinput(HSCPRC * hp, STRPTR filename)
  410. {
  411.     hsc_message(hp, MSG_NO_INPUT,
  412.                 "can not open %q for input: %s",
  413.                 filename, strerror(errno));
  414. }
  415.  
  416. VOID hsc_msg_nouri(HSCPRC * hp, STRPTR filename, STRPTR uriname, STRPTR note)
  417. {
  418.     if (note)
  419.     {
  420.         hsc_message(hp, MSG_NO_URIPATH,
  421.                     "file %q for URI %q not found (%s)",
  422.                     filename, uriname, note);
  423.     }
  424.     else
  425.     {
  426.         hsc_message(hp, MSG_NO_URIPATH,
  427.                     "file %q for URI %q not found",
  428.                     filename, uriname);
  429.     }
  430. }
  431.  
  432. /*
  433.  * show up enforcer hit
  434.  */
  435. VOID enforcerHit(VOID)
  436. {
  437.     fputs("WORD-WRITE to  00000000        data=0000       PC: 0325B854\n"
  438.           "USP:  034735C8 SR: 0004 SW: 0729  (U0)(-)(-)  TCB: 03349A28\n"
  439.         "Name: \"Shell Process\"  CLI: \"hsc\"  Hunk 0000 Offset 00000074\n"
  440.           "\n"
  441.           "LONG-READ from AAAA4444                        PC: 0325B858\n"
  442.           "USP:  034735C8 SR: 0015 SW: 0749  (U0)(F)(-)  TCB: 03349A28\n"
  443.         "Name: \"Shell Process\"  CLI: \"hsc\"  Hunk 0000 Offset 00000078\n"
  444.           "\n"
  445.           "BYTE-WRITE to  00000101        data=11         PC: 0325B862\n"
  446.           "USP:  034735C8 SR: 0010 SW: 0711  (U0)(F)(D)  TCB: 03349A28\n"
  447.         "Name: \"Shell Process\"  CLI: \"hsc\"  Hunk 0000 Offset 00000082\n"
  448.           "\n"
  449.           "LONG-WRITE to  00000102        data=00000000   PC: 0325B86A\n"
  450.           "USP:  034735C8 SR: 0014 SW: 0709  (U0)(-)(D)  TCB: 03349A28\n"
  451.         "Name: \"Shell Process\"  CLI: \"hsc\"  Hunk 0000 Offset 0000008A\n"
  452.           "\n"
  453.           "Alert !! Alert 35000000     TCB: 03349A28     USP: 034735C4\n"
  454.           "Data: 00000000 DDDD1111 DDDD2222 DDDD3333 0325B802 DDDD5555 DDDD6666 35000000\n"
  455.           "Addr: AAAA0000 AAAA1111 AAAA2222 AAAA3333 AAAA4444 0325B802 00200810 --------\n"
  456.           "Stck: 0325B878 00000000 00FA06D6 00010000 0334A40C 03F46630 00AC4C20 00000000\n",
  457.           stderr);
  458.     strcpy((STRPTR) hsc_message, "die for oil, sucker");        /* crash machine */
  459.     exit(RC_FAIL);              /* just for the case we are still there.. */
  460. }
  461.  
  462.